package com.dataflow.example.util;

import cn.hutool.core.collection.ListUtil;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 盐值读取器
 *
 * @author dx
 */
public class SaltReader {

    private static final String PATH = "E:\\projects\\java\\data-flow\\dataflow\\executor-sample\\src\\main\\resources\\salt.txt";

    public static List<String> readSalts() {
        return readFile();
    }

    private static void saveFile(String content) {
        try (FileWriter fileWriter = new FileWriter(SaltReader.PATH, true)) {
            fileWriter.append(content);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static List<String> readFile() {
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader(SaltReader.PATH))){
            List<String> list = new ArrayList<>();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                list.add(line);
            }
            return list;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ListUtil.empty();
    }

}
